//
//  LGPhotoWayView.m
//  LGSanofiPatient
//
//  Created by 1234 on 2022/10/31.
//  选择拍照方式--弹框

#import "LGPhotoWayView.h"

@interface LGPhotoWayView()

/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIButton *cameraBtn;
/**   */
@property (nonatomic , strong)UIButton *photoBtn;
/**   */
@property (nonatomic , strong)UIButton *cancelBtn;
/**   */
@property (nonatomic , strong)UIView *lineView1;
/**   */
@property (nonatomic , strong)UIView *lineView2;

@end

@implementation LGPhotoWayView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithString:@"#0D0D0D" alpha:0];
        [self addSubview:self.baseView];
        [self.baseView addSubview:self.cameraBtn];
        [self.baseView addSubview:self.photoBtn];
        [self.baseView addSubview:self.cancelBtn];
        [self.baseView addSubview:self.lineView1];
        [self.baseView addSubview:self.lineView2];
        [UIView animateWithDuration:0.3 animations:^{
            self.backgroundColor = [UIColor colorWithString:@"#0D0D0D" alpha:0.7];
            self.baseView.frame = CGRectMake(0, Screen_H-viewPix(200)-bottomSafeBarHeight/3.0, Screen_W, viewPix(250)+bottomSafeBarHeight/3.0);
        }];
    }
    return self;
}

-(void)photoWaySelect:(UIButton *)sender{
    NSString *selectWay = (sender == self.cameraBtn)?@"camera":@"photo";
    if(self.LGSelectPhotoWay){
        self.LGSelectPhotoWay(selectWay);
    }
    [UIView animateWithDuration:0.4 animations:^{
        self.backgroundColor = [UIColor colorWithString:@"#0D0D0D" alpha:0];
        self.baseView.frame = CGRectMake(0, Screen_H, Screen_W, viewPix(250));
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

-(void)cancelBtnAction{
    if (self.LGSelectPhotoCancel) {
        self.LGSelectPhotoCancel();
    }
    [UIView animateWithDuration:0.4 animations:^{
        self.backgroundColor = [UIColor colorWithString:@"#0D0D0D" alpha:0];
        self.baseView.frame = CGRectMake(0, Screen_H, Screen_W, viewPix(250));
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

#pragma mark
#pragma mark ====> 创建控件
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_H, Screen_W, viewPix(250)+bottomSafeBarHeight/3.0)];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 10;
    }
    return _baseView;
}

-(UIButton *)cameraBtn{
    if(!_cameraBtn){
        _cameraBtn = [UIButton buttonWithTitle:@"拍摄" titleFont:LGFont(16) textColor:@"#2B2A37" imageName:@""];
        _cameraBtn.frame = CGRectMake(0, 0, Screen_W, viewPix(60));
        [_cameraBtn addTarget:self action:@selector(photoWaySelect:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cameraBtn;
}

-(UIButton *)photoBtn{
    if(!_photoBtn){
        _photoBtn = [UIButton buttonWithTitle:@"从手机相册选择" titleFont:LGFont(16) textColor:@"#2B2A37" imageName:@""];
        _photoBtn.frame = CGRectMake(0, viewPix(60), Screen_W, viewPix(60));
        [_photoBtn addTarget:self action:@selector(photoWaySelect:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _photoBtn;
}

-(UIButton *)cancelBtn{
    if(!_cancelBtn){
        _cancelBtn = [UIButton buttonWithTitle:@"取消" titleFont:LGFont(16) textColor:@"#2B2A37" imageName:@""];
        _cancelBtn.frame = CGRectMake(0, viewPix(130), Screen_W, viewPix(60));
        [_cancelBtn addTarget:self action:@selector(cancelBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelBtn;
}

-(UIView *)lineView1{
    if(!_lineView1){
        _lineView1 = [[UIView alloc]initWithFrame:CGRectMake(0, viewPix(60), Screen_W, 1)];
        _lineView1.backgroundColor = [UIColor colorWithString:@"#FAFAFA"];
    }
    return _lineView1;
}

-(UIView *)lineView2{
    if(!_lineView2){
        _lineView2 = [[UIView alloc]initWithFrame:CGRectMake(0, viewPix(120), Screen_W, 10)];
        _lineView2.backgroundColor = [UIColor colorWithString:@"#FAFAFA"];
    }
    return _lineView2;
}

@end
